package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.common.core.domain.entity.SysUser;
import com.xjy.system.domain.bo.BaseAuditBo;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysColpaydecVo;
import com.xjy.system.domain.bo.SysColpaydecQueryBo;
import com.xjy.system.domain.bo.SysColpaydecAddBo;
import com.xjy.system.domain.bo.SysColpaydecEditBo;
import com.xjy.system.service.ISysColpaydecService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 收入记账信息Controller
 *
 * @author xjy
 * @date 2022-02-14
 */
@Api(value = "收入记账信息控制器", tags = {"收入记账信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/colpaydec")
public class SysColpaydecController extends BaseController {

    private final ISysColpaydecService iSysColpaydecService;

	/**
	 * 查询收款账户
	 */
	@ApiOperation("查询收款账户")
	@GetMapping("/queryColpayName")
	public AjaxResult<List<SysUser>> queryColpayName(@ApiParam("收款账户名称") @RequestParam("colpayName") String colpayName ) {
		return iSysColpaydecService.queryColpayName(colpayName);
	}
	/**
	 * 查询经办人
	 */
	@ApiOperation("查询经办人")
	@GetMapping("/queryColpayHandler")
	public AjaxResult<List<SysUser>> queryColpayHandler(@ApiParam("经办人名称") @RequestParam("handler") String handler) {
		return iSysColpaydecService.queryColpayHandler(handler);
	}

    /**
     * 查询收入记账信息列表
     */
    @ApiOperation("查询收入记账信息列表")
    @PreAuthorize("@ss.hasPermi('system:colpaydec:list')")
    @GetMapping("/list")
    public TableDataInfo<SysColpaydecVo> list(@Validated SysColpaydecQueryBo bo) {
        return iSysColpaydecService.queryPageList(bo);
    }

    /**
     * 导出收入记账信息列表
     */
    @ApiOperation("导出收入记账信息列表")
    @PreAuthorize("@ss.hasPermi('system:colpaydec:export')")
    @Log(title = "收入记账信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysColpaydecVo> export(@Validated SysColpaydecQueryBo bo) {
        List<SysColpaydecVo> list = iSysColpaydecService.queryList(bo);
        ExcelUtil<SysColpaydecVo> util = new ExcelUtil<SysColpaydecVo>(SysColpaydecVo.class);
        return util.exportExcel(list, "收入记账信息");
    }

    /**
     * 获取收入记账信息详细信息
     */
    @ApiOperation("获取收入记账信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:colpaydec:query')")
    @GetMapping("/{id}")
    public AjaxResult<SysColpaydecVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iSysColpaydecService.queryById(id));
    }

    /**
     * 新增收入记账信息
     */
    @ApiOperation("新增收入记账信息")
    @PreAuthorize("@ss.hasPermi('system:colpaydec:add')")
    @Log(title = "收入记账信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysColpaydecAddBo bo) {
        return toAjax(iSysColpaydecService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改收入记账信息
     */
    @ApiOperation("修改收入记账信息")
    @PreAuthorize("@ss.hasPermi('system:colpaydec:edit')")
    @Log(title = "收入记账信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/edit")
    public AjaxResult<Void> edit(@Validated @RequestBody SysColpaydecEditBo bo) {
        return toAjax(iSysColpaydecService.updateByEditBo(bo) ? 1 : 0);
    }

	/**
	 * 修改收入记账信息
	 */
	@ApiOperation("修改收入记账信息")
	@PreAuthorize("@ss.hasPermi('system:colpaydec:edit')")
	@Log(title = "收入记账信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/audit")
	public synchronized AjaxResult<Void> audit(@Validated @RequestBody BaseAuditBo bo) {
		return toAjax(iSysColpaydecService.auditByEditBo(bo) ? 1 : 0);
	}

    /**
     * 删除收入记账信息
     */
    @ApiOperation("删除收入记账信息")
    @PreAuthorize("@ss.hasPermi('system:colpaydec:remove')")
    @Log(title = "收入记账信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iSysColpaydecService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
